package com.my.hp_hr.contorller;


import com.my.hp_hr.entity.Position;
import com.my.hp_hr.service.PositionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/updatePosition")
public class UpdatePosition extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            req.setCharacterEncoding("utf-8");
            PositionService positionService = new PositionService();
            String id = req.getParameter("position_id");
            Position position=positionService.getPositionById(id);
            Integer id1 = position.getId();
            Integer position_number = position.getPosition_number();
            String name = req.getParameter("name");
            String level = req.getParameter("level");
            String notes = req.getParameter("notes");
            Position position2 = new Position(id1,position_number,name,level,notes);
            positionService.updatePosition(position2);
            req.getRequestDispatcher("pagePosition").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
